home *** CD-ROM | disk | FTP | other *** search
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.Serializable;
- import java.io.Writer;
- import java.util.Vector;
-
- public class IOUtil implements Serializable {
- public static void saveObject(String fileName, Object theObject) throws IOException {
- ObjectOutputStream writingPipe = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(fileName)));
- writingPipe.writeObject(theObject);
- writingPipe.close();
- }
-
- public static Object openObject(String fileName) throws IOException {
- Object theData = new Object();
- ObjectInputStream readingPipe = new ObjectInputStream(new BufferedInputStream(new FileInputStream(fileName)));
-
- try {
- theData = readingPipe.readObject();
- readingPipe.close();
- } catch (ClassNotFoundException var4) {
- System.out.println("Class not found!");
- }
-
- return theData;
- }
-
- public static Vector openTextFile(String fileName) throws IOException {
- Vector temp = new Vector(100, 100);
-
- try {
- boolean exitLoop = false;
- FileInputStream theData = new FileInputStream(fileName);
- BufferedReader readingPipe = new BufferedReader(new InputStreamReader(theData));
-
- do {
- String theString = readingPipe.readLine();
- if (theString != null) {
- temp.addElement(theString);
- } else {
- exitLoop = true;
- }
- } while(!exitLoop);
-
- readingPipe.close();
- return temp;
- } catch (Exception var6) {
- throw new IOException();
- }
- }
-
- public static void saveTextFile(String theFileName, String theText, boolean append) throws IOException {
- BufferedWriter out = new BufferedWriter(new FileWriter(theFileName, append));
- ((Writer)out).write(theText);
- out.close();
- }
-
- public static boolean fileExists(String theFileName) {
- File theFile = new File(theFileName);
- return theFile.exists();
- }
-
- public static boolean deleteFile(String theFileName) throws SecurityException {
- File theFile = new File(theFileName);
- return theFile.delete();
- }
-
- public static String[] dirListing(String path) throws IOException {
- try {
- File temp = new File(path);
- return temp.list();
- } catch (Exception var2) {
- throw new IOException();
- }
- }
-
- public static boolean makeDirectory(String dir) throws Exception {
- try {
- File temp = new File(dir);
- return temp.mkdirs();
- } catch (Exception var2) {
- throw new Exception(((Throwable)var2).toString());
- }
- }
-
- public static void main(String[] args) throws IOException {
- try {
- openTextFile("data/email-list.txt");
- } catch (Exception var2) {
- System.out.println("urf! " + var2);
- }
-
- }
- }
-